package com.lwj.liwanjia.view.activity.personal;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.lwj.liwanjia.R;
import com.lwj.liwanjia.base.BaseActivity;
import com.lwj.liwanjia.bean.YaoqingBean;
import com.lwj.liwanjia.impl.YaoQingView;
import com.lwj.liwanjia.presenter.YaoqingPresenter;
import com.lwj.liwanjia.utils.ShareDialog;
import com.lwj.liwanjia.utils.SpfUtils;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;

/**
 * Created by 001 on 2017/9/11.
 */

public class YaoQingActivity extends BaseActivity implements View.OnClickListener, YaoQingView {

    private TextView tv_back;
    private TextView tv_title;
    private ImageView iv_fenXiang;//分享 按钮
    private TextView tvSum;//人数
    private TextView tvMoney;//积分
    private YaoqingPresenter presenter;
    private String token;

    @Override
    protected void initView() {

        tv_back = (TextView) findViewById(R.id.tv_left);
        tv_title = (TextView) findViewById(R.id.tv_title);
        iv_fenXiang = (ImageView) findViewById(R.id.iv_fenXiang);
        tvSum = (TextView) findViewById(R.id.tv_sum);
        tvMoney = (TextView) findViewById(R.id.tv_money);

        tv_back.setVisibility(View.VISIBLE);
        tv_title.setVisibility(View.VISIBLE);
        tv_title.setText("邀请有礼");

        tv_back.setOnClickListener(this);
        iv_fenXiang.setOnClickListener(this);
        token = SpfUtils.getSpfUtils(this).getToken();
        presenter = new YaoqingPresenter(this);
    }

    @Override
    protected void initData() {
        presenter.getYaoqingData(token);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_yao_qing;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //返回
            case R.id.tv_left:
                finish();
                break;
            //分享
            case R.id.iv_fenXiang:
                ShareDialog dialog = new ShareDialog(this, "", "http://www.liwanj.com/share/share.html", "让购物成为时尚,让生活充满希望。赶快下载APP吧!", "利万嘉将带给你更加完美的购物体验,更具品质的商品。只有你想不到,没有我卖不了!");
                dialog.show();
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        UMShareAPI.get(this).release();
        if (presenter != null) {
            presenter = null;
        }
    }

    @Override
    public void showError(Exception e) {
        Toast.makeText(this, "数据加载失败", Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onResume() {
        super.onResume();
        initData();
    }

    @Override
    public void getYaoqingData(YaoqingBean yaoqingBean) {
        if (yaoqingBean.getState() == 0) {
            Toast.makeText(this, "接口有误", Toast.LENGTH_SHORT).show();
        } else if (yaoqingBean.getState() == 1) {
            tvSum.setText(yaoqingBean.getData().getReferrer() + "");
            tvMoney.setText(yaoqingBean.getData().getIntegral() + "");
        }
    }

}
